package org.flashbrighton.as3bots.geom
{
	import org.flashbrighton.as3bots.utils.NumberUtils;
	
	//TODO: change to public vars
	public class Circle
	{
		private var mX:Number;
		private var mY:Number;
		private var mR:Number;
		private var mRot:Number;
		
		
		/**
		 * Constructor
		 * @param px the x position (centre)
		 * @param py the y position (centre)
		 * @param r the radius
		 * 
		 */		
		public function Circle(px:Number = 0, py:Number = 0, ra:Number = 0, ro:Number = 0):void
		{
			mX = px;
			mY = py;
			mR = ra;
			mRot = ro;
			
			
		}
		
		/**
		 * Number that specifies the component's horizontal position, in pixels.
		 */		
		public function get x():Number
		{
			return mX;
		}
		/**
		 * 
		 * @private
		 * 
		 */				
		public function set x(param:Number):void
		{
			mX = param;
		}
		
		/**
		 * Number that specifies the component's verticle position, in pixels.
		 */	
		public function get y():Number
		{
			return mY;
		}
		/**
		 * 
		 * @private
		 * 
		 */				
		public function set y(param:Number):void
		{
			mY = param;
		}
		
				
		public function get radius():Number
		{
			return mR;
		}
				
		public function set radius(param:Number):void
		{
			mR = param;
		}
		
		public function get rotation():Number
		{
			return mRot;
		}
				
		public function set rotation(param:Number):void
		{
			mRot = param;
		}
		
		public function get top():Number
		{
			return y-radius;
		}
		
		public function get bottom():Number
		{
			return y+radius;
		}
		
		public function get left():Number
		{
			return x-radius;
		}
		
		public function get right():Number
		{
			return x+radius;
		}
		
		public function get circumference ():Number
		{
			return Math.PI*(radius*2)
		}
		
		public function get area ():Number
		{
			return Math.PI*(radius*radius)
		}
		
		public function boundingTest(c:Circle):Boolean
		{
			
			return	(
						top < c.bottom && 
						bottom > c.top && 
						right > c.left && 
						left < c.right
					) 
			
						
		}
		
		public function hitTest(c:Circle):Boolean
		{
			
			return ( boundingTest(c) ) ? internalHitTest(c) : false
			
								
		}
		
		public function contains(c:Circle):Boolean
		{
			
			return ( boundingTest(c) ) ? internalContains(c) : false
			
								
		}
		
		
		
		
		
		
		
		private function internalContains(c:Circle):Boolean
		{
			
			return (hypotLength(c) < radius - c.radius)
			
								
		}
		
		private function internalHitTest(c:Circle):Boolean
		{
			
			return (hypotLength(c) < radius + c.radius)
							
		}
		
		private function hypotLength(c:Circle):Number{
			
			var diffX:Number, diffY:Number
			
			diffX = x - c.x;
			diffY = y - c.y;
			
			return Math.sqrt( (diffX * diffX) + (diffY * diffY) )
			
		}
		

		

	}
}